<@pp.dropOutputFile/>
<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<@pp.changeOutputFile name="/main/java/${package}/common/Outcome.java"/>
<#assign package = doc.groupid?replace("/", ".")>
package ${package}.common;

import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class Outcome {
	private Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
	
    private int result;    // The number of result 
    private String message;    // Message of result
    private String msg;	// Message tag
    private String detail; // The detail of result;  
    private Object data;	// Data carrier
    private Integer total;

    public Outcome(){
    	result = -1;
    	total = 0;
    	data = 0;
    	message = "";
    	detail = "";
    }
    
    public Outcome(int r){
    	result = r;
    	total = 0;
    	data = 0;
    	message = "";
    	detail = "";
    }

    public Map<String, Object> toMap(){
    	Map<String, Object> res = new HashMap<String, Object>();
    	res.put("res", success() ? 0 : -1);
    	res.put("message", message);
    	res.put("detail", detail);
    	res.put("total", total);
    	res.put("data", gson.toJson(data));
    	
    	return res;
    }
    
    public boolean success(){
    	return result == 0;
    }
    
    public int getResult() {  
        return result;  
    } 
    
    public void setResult(int r) {  
        result = r;  
    }
    
    public String getMessage() {  
        return message;  
    }
    
    public void setMessage(String m) {  
        message = m;  
    }
    
     public String getDetail() {  
        return detail;  
    }
    
    public void setDetail(String d) {  
        detail = d;  
    }

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}
}